﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TeachPostRelation.aspx.cs" Inherits="Basic4Net.OAWeb.Module_Base.TeachPostRelation" %>

<%@ Register Assembly="Controls" Namespace="Basic4Net.Controls" TagPrefix="webdiyer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link type="text/css" rel="stylesheet" href="../App_Themes/ui-lightness/main.css" />
    <script type="text/javascript" src="../Scripts/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="../Scripts/Common.js"></script>   

    <script>

        //选中行高亮
        function SetHightLight(obj) {
            if (obj != null)
                obj.style.backgroundColor = "#fffccf";

            var table = document.getElementById('table');
            for (var i = 0; i < table.rows.length; i++) {
                var row = table.rows[i];
                if (row != null && row.rowIndex != obj.rowIndex) {
                    row.style.backgroundColor = "#ffffff";
                }
            }
        }
        //关闭遮罩层
        function CloseMask(formId) {
            ClosePopForm(formId, true);
            hideMask();
        }

        function ShowSetPostWindow() {
            arr = [];
            $("input[type='checkbox'][id!='chkSelectAll'][checked]").val(
            function () {
                arr.push(Number(this.attributes["postid"].value));
            }
            );

            if (arr.length < 1) {
                showMassgeBox("提示", "没有选中任何教师.", 1);
                return;
            }
            ShowPopForm("popTable", "formTitle", "设置教工职务");
            showMask();
           
        }

        function ShowSetWindow() {
         //   var postName = document.getElementById('dropList2').value;
            showConfirmBox("设置教工职务", "确定设置被勾选教工的职务?", SetPost, null);
        }

        function SetPost() {
            if (document.getElementById('table') != null) {
                var teachArr = new Array();
                var oldpostArr = new Array();
                var postId = document.getElementById('dropList2').value;
                var table = document.getElementById('table');
                var type = document.getElementById('rdoAdd').checked == true ? 1 : 2;

                $("input[type='checkbox'][id!='chkSelectAll'][checked]").val(
                function () {
                    teachArr.push(Number(this.attributes["teacherId"].value));
                    oldpostArr.push(Number(this.attributes["postid"].value));
                }
                );

                if (teachArr.length > 0) {
                    if (type == 1) {//添加职务
                        PageMethods.AddTeachPost(teachArr, postId, function (succ) {
                            if (succ > 0) {
                                document.getElementById('dropList1').value = postId;
                                CloseMask('popTable');
                                Bind();
                            }
                        }, function (err) {
                            showMassgeBox("提示", "操作失败", 1, null);
                        });  
                    }
                    else {//修改职务
                        //var oldPostId = document.getElementById('dropList1').value;
                        PageMethods.UpdateTeachPost(teachArr, postId, oldpostArr, function (succ) {
                            if (succ > 0) {
                                document.getElementById('dropList1').value = postId;
                                CloseMask('popTable');
                                Bind();
                            }
                        }, function (err) {
                            showMassgeBox("提示", "操作失败", 1, null);
                        });  
                    }
                    
                    
                }
                else {
                    showMassgeBox("提示", "您还未选择要设置的教工", 1, null);
                    return;
                }

                 
            }

        }

        function Bind() {
            teachArr = new Array();
//            var teachName = document.getElementById('txtTeachName').value;
            var teachCode = document.getElementById('txtTeachCode').value; 
//            document.getElementById('TeachName').value = teachName;
            document.getElementById('TeachCode').value = teachCode;
            document.getElementById('btnItemBind').click();
        }

        function SelectALl() {
            var isCheck = document.getElementById('chkAll').checked; 
             if (document.getElementById('table') != null) {
                var table = document.getElementById('table');
                for (var i = 1; i < table.rows.length; i++) {
                    var row = table.rows[i];
                    if (row.cells[0].all != null && row.cells[0].all.length > 0) {
                        row.cells[0].all[0].checked = document.getElementById('chkAll').checked;  
                    }
                }
             }
        }

        function SetRdoAdd(obj) {
//            obj.checked = !obj.checked;
//            document.getElementById('rdoUpdate').checked = !obj.checked;
        }

        function SetRdoUpdate(obj) {
//            obj.checked = !obj.checked;
//            document.getElementById('rdoAdd').checked = !obj.checked;
        }

    </script>
</head>
<body onload="myload();">
    <form id="form1" runat="server">
   <div style="overflow-y: auto; overflow-x: none; height: 98%;">
            <div class="mainWarp">
                <div class="pageBody" style="height: 96%;">
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                    </asp:ScriptManager>  
                        
                    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                        <ContentTemplate>
                        <ul class="butList">
                            <li>
                                <asp:DropDownList ID="dropList1" runat="server">
                                    
                                </asp:DropDownList> 
                            </li>
                             <li>
                                输入姓名或工号：<input id="txtTeachCode" type="text" /><%--姓名:<input id="txtTeachName" type="text" />--%>
                             </li>
                            <li>
                                <input type="button" value="查询" class="commonBut" id="btnAddItem" onclick="Bind();" />
                            </li>
                            <li>
                                <input type="button" value="批量设置教工职务" class="commonBut" id="btnSetPost" onclick="ShowSetPostWindow();" />
                            </li>
                        </ul>  
                                
                        <div style="overflow-y: auto; overflow-x: none; height: 90%;">
                            <table id="table" class="useList" style="width: 95%">
                                <tr >
                                    <th  style="width: 5%">
                                    <input type="checkbox" onclick="SelectALl();" id="chkAll"/>
                                        </th>
                                    <th style="text-align: left; padding-left: 5px;width: 20%">
                                        职务</th>
                                    <th style="text-align: left; padding-left: 5px;width: 10%">
                                        工号</th> 
                                    <th style="text-align: left; padding-left: 5px;width: 10%">
                                        姓名</th>
                                    <th style="text-align: left; padding-left: 5px;">
                                        性别</th>
                                   <th>
                                        出生日期</th>
                                </tr>
                        <asp:Repeater ID="Repeater1" runat="server">    
                            <ItemTemplate> 
                                <tr itemid="<%# Eval("TeacherID")%>"  onclick="SetHightLight(this);" >
                                    <td><input type="checkbox" teacherId="<%# Eval("TeacherID")%>"  postid="<%# Eval("PostID") %>"/></td>
                                    <td style="text-align: left; padding-left: 5px;"><%# Eval("PostName")%></td>
                                    <td style="text-align: left; padding-left: 5px;"><%# Eval("TeachCode")%></td>
                                    <td style="text-align: left; padding-left: 5px;"><%# Eval("TeachName")%></td>
                                    <td style="text-align: left; padding-left: 5px;"><%# Eval("Sexy")%></td>
                                    <td><%# Eval("BirthDay")%></td>
                                     </tr> 
                            </ItemTemplate>
                            </asp:Repeater> 
                        </table> 
                        </div>  
                     <div style=" text-align:left; padding-top:8px;">
                            <webdiyer:BNPager ID="aspNetPager" runat="server" PageSize="20" Width=680
                                 OnPageChanged="AspNetPagerPageChanged" >
                            </webdiyer:BNPager>
                         </div>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnItemBind" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="aspNetPager" EventName="PageChanged" />
                </Triggers>
            </asp:UpdatePanel>

            <%--服务器端控件层--%>
            <div style="display:none;">
                <asp:Button runat="server" ID="btnItemBind" onclick="btnItemBind_Click"   />
                <asp:TextBox runat="server" ID="TeachName" />
                <asp:TextBox runat="server" ID="TeachCode" /> 
            </div>
                  
                     
                <%-- 添加设置教工职务弹出层 --%>
                <div id="popTable" class="layoutWarp" style="display: none; width: 400px; overflow: inherit;">
                    <div class="title">
                        <span id="formTitle">设置</span> <a title="关闭" onclick="return CloseMask('popTable');">
                            关闭</a>
                    </div>
                    <table>
                        <tr>
                            <td style=" text-align:left;"><input type="radio" id="rdoAdd" name="rdo" value="1" onclick="SetRdoAdd(this)" />添加职务</td><td style=" text-align:left;"><input type="radio" name="rdo" id="rdoUpdate" value="2" onclick="SetRdoUpdate(this);"/>更换职务</td>
                        </tr>
                        <tr><td style=" text-align:left; padding-left:5px;">名称：</td>
                            <td style=" text-align:left;">
                                <asp:DropDownList ID="dropList2" runat="server">
                                    
                                </asp:DropDownList> 
                            </td>
                        <tr> 
                            <td colspan="2">
                                <input type="button" id="btnOK" value="确定"class="commonBut" onclick="SetPost();" />
                                <input type="button" id="btnCancel" value="取消" class="commonBut" onclick="return CloseMask('popTable');"/>
                            </td>
                        </tr>
                    </table>  
                </div>  

            </div>
        </form>
   
</body>
</html>
<script type="text/javascript">
    function myload() {
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(EndRequestHandler);
    }
    function EndRequestHandler() {
        $("input[type='submit']").addClass("commonBut");
    }

    $("input[type='submit']").addClass("commonBut");
</script>